import { Body, Controller, Get, Post, Req } from '@nestjs/common';
import { UserService } from './user.service';
import { ReqAttrs } from '../../constant';
import { ResponseUtilService } from '@app/response-util';
import { DtoPipe } from 'apps/admin/src/pipe/dto/dto.pipe';
import UpdateInfoDto from './dto/info.dto';

@Controller('user')
export class UserController {
    constructor(
        private readonly service:UserService
    ) {}

    @Get('balance/list')
    async balanceList(@Req() req) {
        const r = await this.service.getUserBalance(req[ReqAttrs.USER_ID])
        return ResponseUtilService.successRes(r)
    }


    @Post('update/info')
    async update(@Body(new DtoPipe({whitelist : true, skipMissingProperties : true})) dto:UpdateInfoDto, @Req() req) {
        try {
            const r = await this.service.updateInfo(dto, req[ReqAttrs.USER_ID])
            return r ? ResponseUtilService.successRes() : ResponseUtilService.failRes()
        } catch (error) {
            return ResponseUtilService.failRes(error.message)
        }
    }
}
